package at.irian.jsfatwork.broker.application;

import at.irian.jsfatwork.broker.domain.account.Accounting;
import at.irian.jsfatwork.broker.domain.client.Client;
import at.irian.jsfatwork.broker.domain.client.ClientRepository;
import at.irian.jsfatwork.broker.domain.stock.StockExchange;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

/**
 * @author Thomas Spiegl
 */
@Service
public class TestDataLoader {

    @Autowired
    private ClientRepository clientRepository;

    @Autowired
    private Accounting accounting;

    @Autowired
    private StockExchange stockExchange;

    @Transactional
    public void loadTestData() {

        Client client = clientRepository.createPersistentClient("Thomas", "Spiegl", "tomsp");
        accounting.createClearingAccount(client).credit(new BigDecimal(100000));
        accounting.createSecuritiesAccount(client);

        Client client2 = clientRepository.createPersistentClient("Manfred", "Geiler", "manolito");
        accounting.createClearingAccount(client2).credit(new BigDecimal(100000));
        accounting.createSecuritiesAccount(client2);

        stockExchange.createStock("GOOG");
        stockExchange.createStock("APPL");
    }

}
